﻿using DDE_Server.Common;
using DDE_Server.Object;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DDE_Server.View
{
    public partial class StrategyBuilderForm : Form
    {

        private DataEntry ent = null;

        public DataEntry Entry {
            set {
                ent = value;
            }
            get {
                ent = GetData();
                return ent;
            }
        }

        public StrategyBuilderForm()
        {
            InitializeComponent();
            Init_Compare();
            Init_TopAvg();
            Init_Bid();

        }

        public DataEntry GetData()
        {
            if (ent == null)
            {
                ent = new DataEntry();
            }
            
           //ent.status 

           ent.timerCount = ent.timer = TimeSpan.FromMinutes(Convert.ToDouble(timer_txt.Text));

           ent.bidOffer =  (BidOffer)bigOffer_combx.SelectedIndex;

           ent.price = Convert.ToDouble(valueBid_txt.Text);

           ent.StripName = name_txt.Text;
           //ent.beginDate = 
           //ent.endDate =
           ent.distpatch = (Distpatch)top_combx.SelectedIndex;

           ent.condition = (Compare)compare_combx.SelectedIndex;

           ent.priceConditional = Convert.ToDouble(valueConditional_txt.Text);

           ent.status = Result.FALSE;
           return ent;

        }

        private void Init_Compare()
        {

            for (Compare i = Compare.G; i < Compare.E; i++)
            {
                compare_combx.Items.Add(Global.Text(i));
            }
        }

        private void Init_TopAvg()
        {

            for (Distpatch i = Distpatch.TOP1; i < Distpatch.Max; i++)
            {
                top_combx.Items.Add(Global.Text(i));
            }
        }

        private void Init_Bid()
        {

            for (BidOffer i = BidOffer.B; i < BidOffer.Max; i++)
            {
                bigOffer_combx.Items.Add(Global.Text(i));
            }
        }

        private void ok_btn_Click(object sender, EventArgs e)
        {
            //this.ok_btn.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void cancel_btn_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void valueBid_txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar)&& e.KeyChar != 8)
            {
                e.Handled = true; // input is not passed on to the control(TextBox)
                MessageBox.Show("You can type Only integer values");
            }
        }

        private void valueConditional_txt_KeyPress(object sender, KeyPressEventArgs e)
        {
			if (!Char.IsDigit(e.KeyChar) && e.KeyChar != 8)
            {
                e.Handled = true; // input is not passed on to the control(TextBox)
                MessageBox.Show("You can type Only integer values");
            }
        }

        private void timer_txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && e.KeyChar != '.' && e.KeyChar != 8)
            {
                e.Handled = true; // input is not passed on to the control(TextBox)
                MessageBox.Show("You can type Only integer/float values");
            }
        }
    }
}
